import Vue from "vue"
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        name: '张三',
        number: 0
    },
    getters: {
        getTitle (state) {
            return `你好！${state.name}`
        }
    },
    mutations: { // 修改state
        setNumber (state, payload) {
            state.number = payload.number
        }
    },
    actions: {
        setNum (content) {
            return new Promise(resolve => {
                setTimeout(() => {
                    content.commit('setNumber', { number: 555 })
                    resolve()
                },1000)
            })
        }
    }
})

export default store